package com.lmt_16;

import org.w3c.dom.ls.LSInput;

import java.util.ArrayList;
import java.util.List;

public class Desk {
    private List<String> list = new ArrayList<>();

    public synchronized void put() {
        String name = Thread.currentThread().getName();
        if (list.size() == 1){
            this.notifyAll();
            try {
                this.wait();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }else {
            list.add(name + "生产了一个");
            System.out.println(name+" 生产了一个");
            this.notifyAll();
        }
    }

    public synchronized void get() {
        String name = Thread.currentThread().getName();
        if (list.isEmpty()){
            this.notifyAll();
            try {
                this.wait();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        else {
            list.remove(0);
            System.out.println(name+"取出了一个");
            this.notifyAll();
        }
    }
}
